import { reactive } from 'vue'
import { downloadFile } from "@/utils/downLoad"
type CallBackType = ((...args: any[]) => string) | string
export default function useImport() {
  /**导入参数 */
  const importData = reactive({
    data: {
      importShow: false,
      upLoadUrl: '',
    },
  })
 
  /**
   * @method 打开导入弹窗
   * @param callBack 获取导入地址函数 / 导入地址
   */
  function handleImport<T>(callBack: T extends CallBackType ? T : never) {
    importData.data.upLoadUrl = typeof callBack === 'function' ? callBack() : callBack
    importData.data.importShow = true
  }
 
  /**
   * @method 下载模板
   */
  async function onDownload(callBack: () => Promise<T>) {
    try {
      const { Success, Tag, ResultCode } = await callBack()
      if (ResultCode === 200 && Success) {
        
      }
    } catch (error) {
      console.log('下载模板error', error)
    }
  }
 
  /**
   * @method 导入弹窗关闭事件
   * @param is 是否关闭
   * @param callBack 关闭后回调(一般为重新请求)
   */
  function importClosed(is: boolean, callBack: (...args: any[]) => void) {
    importData.data.importShow = is
    callBack()
  }
 
  return {
    importData,
    importClosed,
    onDownload,
    handleImport,
  }
}